"""
Author : sunshicheng
DateTime : 2021/5/18.9:15 上午
FileName : assert_locust.py
Desc: 
"""
import sys
from locust import TaskSet, HttpUser, task, constant

sys.path.append('..')
from config.base_info import Static_info as si
from config.user_token import Token

token = Token('1822628729')
headers = token.test_token()



class Assert_test(TaskSet):
    @task
    def test_range(self):
        data = {"account": "sunshicheng"}
        # 添加断言的固定写法，设置 catch_response 捕获请求结果
        with self.client.get(si.inter['saas']['saas_permission'], params=data, headers=headers, name='获取用户权限',
                             catch_response=True) as result:
            # 耗时多少
            print('耗时', result.elapsed.total_seconds())
            # 结果的值在不在里
            if 'SUCCESS。' in result.text:
                result.success()
            else:
                # 错误信息可以自己定义
                result.failure('这次失败了。')


class TesterUser(HttpUser):
    tasks = [Assert_test]
    wait_time = constant(0.1)
